$('#rksh_tabs').tabs({

    border: false,
    onSelect: function (title) {
        if (title == "采购单打印") {
            // 加载合同文本
            $.ajax({
                type: "POST",
                url: $.webPath() + '/kcgl/rksh/rkshDetail?rksh.id='+$("#rksh_id").val(),
                dataType: "html",
                beforeSend: function () {
                    $.messager.progress();
                },
                success: function (data) {
                    $.messager.progress("close");
                    $('#rkshdetail_rksh_id').html(data);
                    if (data.statusCode == 300) {
                    }
                    if (data.statusCode == 200) {
                    }
                }
            });
        }
    }
});

$(function(){
    $("#rksh_tabs .previewImg").lightbox({
        fitToScreen: true,
        loopImages: true,
        imageClickClose: false,
        disableNavbarLinks: true
    });
    $("#cgd_cgdmx_table").datagrid({
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

    $("#cgd_cgdfy_table").datagrid({
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

    $("#rksh_dhdmx_table").datagrid({
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })
})


//  检查插件
function rksh_detail_checkIsInstall() {
    try {
        var LODOP = getLodop(document.getElementById('RKSH_LODOP_OB'), document.getElementById('RKSH_LODOP_EM'));
        if ((LODOP != null) && (typeof(LODOP.VERSION) != "undefined"))
            alert("本机已成功安装过Lodop控件!\n  版本号:" + LODOP.VERSION);
    } catch (err) {
        alert("Error:本机未安装或需要升级!");
    }
};

// 打印预览.
function rksh_detail_printPreview() {
    var LODOP = getLodop(document.getElementById('RKSH_LODOP_OB'), document.getElementById('RKSH_LODOP_EM'));
    LODOP.PRINT_INIT("预览采购单");
//    var inputs = document.getElementById("page").getElementsByTagName("input");
//    for (var i = 0; i < inputs.length; i++) {
//        inputs[i].setAttribute("value", inputs[i].value);
//    }
    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltop = strBodyStyle + "<div class='textcon'>" + document.getElementById("rkshdetail_print_id").innerHTML + "</div>";
    var strFormHtmlbody = strBodyStyle + "<div class='textcon'>" + document.getElementById("rkshdetail_rksh_id").innerHTML + "</div>";
    var strFormHtmlBottom = strBodyStyle + "<div class='textcon'>" + document.getElementById("rkshdy_print_end").innerHTML+"</div>";

//    LODOP.SET_PRINT_PAGESIZE(0, '2640', '2790', "CreateCustomPage");
//    LODOP.ADD_PRINT_HTM(50, 80, "82%", "90%", strFormHtmltop + strFormHtmlbody + strFormHtmlBottom);
    LODOP.ADD_PRINT_TABLE(135, "1.5%", "90%", 350, strFormHtmlbody);
    LODOP.SET_PRINT_STYLEA(0,"Vorient",3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltop);
    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
    LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottom);
    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
    LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);
//    LODOP.ADD_PRINT_BARCODE(20, "85%", 90, 90, 'QRCode', cgd_cgdh + " " + cgd_ewmtime);
//    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.ADD_PRINT_TEXT(5,"80%",135,20,"总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0,"ItemType",2);
    LODOP.SET_PRINT_STYLEA(0,"Horient",1);
    LODOP.PREVIEW();
}

// 打印
function rksh_detail_print() {
    var LODOP = getLodop(document.getElementById('RKSH_LODOP_OB'), document.getElementById('RKSH_LODOP_EM'));
    LODOP.PRINT_INIT("打印采购单");
    LODOP.SET_PRINT_STYLE("FontSize", 18);

//    var inputs = document.getElementById("page").getElementsByTagName("input");
//    for (var i = 0; i < inputs.length; i++) {
//        inputs[i].setAttribute("value", inputs[i].value);
//    }
    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltop = strBodyStyle + "<div class='textcon'>" + document.getElementById("rkshdetail_print_id").innerHTML + "</div>";
    var strFormHtmlbody = strBodyStyle +"<div class='textcon'>" + document.getElementById("rkshdetail_rksh_id").innerHTML + "</div>";
    var strFormHtmlBottom = strBodyStyle +"<div class='textcon'>" + document.getElementById("rkshdy_print_end").innerHTML+"</div>";

//    LODOP.SET_PRINT_PAGESIZE(0, '2640', '2790', "CreateCustomPage");
//    LODOP.ADD_PRINT_HTM(50, 80, "82%", "90%", strFormHtmltop + strFormHtmlbody + strFormHtmlBottom);
    LODOP.ADD_PRINT_TABLE(135, "1.5%", "90%", 350, strFormHtmlbody);
    LODOP.SET_PRINT_STYLEA(0,"Vorient",3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltop);
    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
    LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottom);
    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
    LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);
//    LODOP.ADD_PRINT_BARCODE(20, "85%", 90, 90, 'QRCode', cgd_cgdh + " " + cgd_ewmtime);
//    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.ADD_PRINT_TEXT(5,"80%",135,20,"总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0,"ItemType",2);
    LODOP.SET_PRINT_STYLEA(0,"Horient",1);
    LODOP.PREVIEW();
}
$(function () {
    initDhdmx();
})

function initDhdmx(){
    //到货单明细
    $("#rksh_dhdmx_table").datagrid({
        url:$.webPath() + '/kcgl/dhd/dhdList?cgdId=' + $("#rksh_id").val(),
        fitColumns:true,
        singleSelect:true,
        fit:true,
        checkOnSelect:false,
        selectOnCheck:false,
        rownumbers:true,
        columns:[
            [
                {field:'id', title:'ID', hidden:true},
                {field:'cgdmxId', title:'采购单明细ID', hidden:true},
                {field:'dhrq', title:'到货日期', width:50},
                {field:'wz.code', title:'物资编码', width:50},
                {field:'wz.name', title:'物资名称', width:40},
                {field:'wz.ggxh', title:'规格型号', width:30},
                {field:'cd', title:'产地', width:30},
                {field:'js', title:'件数', width:50},
                {field:'cz', title:'称重', width:60},
                {field:'sssl', title:'实收数量', width:60,
                    formatter:function(value){
                        var val = formatSlForHtml(value);
                        return val;
                    }},
                {field:'ysjl', title:'验收结论', width:45},
                {field:'zt', title:'状态', width:25,
                    formatter:function (value) {
                        if (value == 'ybc') {
                            return '已保存';
                        } else if (value == "yys") {
                            return '已验收';
                        }
                    }
                }
            ]
        ],
        onDblClickCell:function (index, field, value) {
            if (field == "dhrq") {
                var record = $("#rksh_dhdmx_table").datagrid("getSelected")
                if(record){
                    validate_sreach_detail("到货单信息");
                }
            }
        }
    })
}

//查询到货单信息的方法
function validate_sreach_detail(title) {
    var record = $("#rksh_dhdmx_table").datagrid("getSelected");
    var rkshId = $("#rksh_id").val();
    var data = {type:"val", dhdId:record.id, rkshId:rkshId};
    var href = $.webPath() + "/kcgl/dhd/rksh_dhd_detail";
    dhd_showDetailDialog1(title, href, data);
}
//查询到货单验收信息弹出窗口
function dhd_showDetailDialog1(title, href, data) {
    var win = $.window({
        title:title,
        width:800,
        height:500,
        cache:false,
        url:href,
        data:data,
        modal:true
    });
}

function viewRkshCghtDetail(id) {
    $.window({
        title:'详细信息',
        iconCls:'icon-tip',
        url:$.webPath() + "/htgl/cghtgl/cghtgl_detail?cghtId=" + id ,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}
